package com.cq.androidtools.recycleview.table

import com.cq.androidtools.databinding.GridRecycleview3Binding
import com.cq.androidtools.jetpack.databinding.DataBindingActivity
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext


/**
 * 作者: CQ
 * 日期: 2021-03-16
 * 说明: 实例
 */
class Recycleview3Activity : DataBindingActivity<GridRecycleview3Binding>() {

    override fun GridRecycleview3Binding.initBinding() {
        GlobalScope.launch(Dispatchers.Main) {
            init()
            mBinding.gridRecyclerView.onRefreshRV()
            mBinding.gridRecyclerView.setOnSlideListener(mBinding.gridRecyclerView1)
            mBinding.gridRecyclerView1.setOnSlideListener(mBinding.gridRecyclerView)
        }
    }

    suspend fun init() = withContext(Dispatchers.IO){
        val listTop = mutableListOf<TableDataBean>() //                for (i in mutableListOf("A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "L", "M", "N", "O", "P", "Q", "R")) {
        for (i in mutableListOf("A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "L", "M", "N", "O", "P", "Q", "R")) {
            val twoDimenData = TableDataBean()
            twoDimenData.type = 0
            twoDimenData.gg1dm = i
            listTop.add(twoDimenData)
        }

        val listLeft = mutableListOf<TableDataBean>()
        for (i in 1..98) {
            val twoDimenData = TableDataBean()
            twoDimenData.type = 1
            twoDimenData.gg2dm = i.toString()
            listLeft.add(twoDimenData)
        }

        val listContent = mutableListOf<TableDataBean>()
        for (j in 0 until listTop.size) {
            for (i in 0 until listLeft.size) {
                val twoDimenData = TableDataBean()
                twoDimenData.value = listContent.size + 1
                twoDimenData.type = 2
                twoDimenData.gg1dm = listTop[j].gg1dm
                twoDimenData.gg2dm = listLeft[i].gg2dm
                listContent.add(twoDimenData)
            }
        }
        mBinding.gridRecyclerView.setDataTop(listTop)
        mBinding.gridRecyclerView.setDataLeft(listLeft)
        mBinding.gridRecyclerView.setDataContent(listContent)
    }

}

